package de.fhhof.vinf.ssp.ticketcenter.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class LoginServlet
 */
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoginServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		out.write("<div id=\"outrightcolumn\">");
			out.write("<div id=\"inrightcolumn\">");
			this.printLoginForm(out, response);
	}
	
	/**
	 * Generiert die Maske zum Anmelden auf der Homepage.
	 * @param out	PrintWriter des Servlets, in den die Ausgabe geschrieben wird.
	 * @param response 
	 */
	private void printLoginForm(PrintWriter out, HttpServletResponse response) {
		out.write("<form action=\"" + response.encodeURL("./CheckLogin") + "\" method=\"post\">");
		out.write("<table><tr><td><table><tr><td>");
			out.write("<input type=\"text\" name \"email\" value=\"E-Mail\" size =\"20\" /></td></tr><tr><td>");
			out.write("<input type=\"password\" name \"password\" value=\"Passwort\" size =\"20\" /></td></tr></table></td><td>");
		out.write("<input type=\"submit\" value=\"Login\" class=\"Button\" /></td></tr></table></form>");
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
